package nemeanshop;

import GUInemeanshop.GUIContent;
import java.awt.Toolkit;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Ragnar
 */
public class TimeOut implements Runnable
{
    private boolean state;
    private long start;
    private long stop;
    private int minutes = 2;
    private GUIContent content;
    
    public TimeOut(GUIContent content, int minutes)
    {
        this.state = false;
        this.content = content;
        this.minutes = minutes;
        this.start = System.currentTimeMillis();
    }
    
    public void run()
    {
        this.init();
        while(!this.state)
        {
            this.content.checkProducts();
            this.stop = System.currentTimeMillis();
            //System.out.println("" + (this.stop - this.start));
            if ((this.stop - this.start) > (1000*60*this.minutes))
            {
                this.content.logOut();
                this.state = true;
            }
            
            try
            {
                Thread.sleep(1000);
            }
            catch (InterruptedException ex)
            {
                Logger.getLogger(TimeOut.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
    public void init()
    {
        state = false;
        start = System.currentTimeMillis();
    }
    
    public void setState()
    {
        state = true;
        start = 0;
        stop = 0;
    }
    
    public void update()
    {
        start = System.currentTimeMillis();
        state = false;
    }
    
    public void update(int minutes)
    {
        start = System.currentTimeMillis();
        state = false;
        this.minutes = minutes;
    }
    
    public int getMinutes()
    {
        return this.minutes;
    }
}
